package com.example.warehouse_manager.controller;

import com.example.warehouse_manager.entity.ProductType;
import com.example.warehouse_manager.entity.Result;
import com.example.warehouse_manager.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/productCategory")
public class ProductTypeController {

    @Autowired
    private ProductTypeService productTypeService;


    //查询商品分类树
    @RequestMapping("/product-category-tree")
    public Result productCateGoryTree(){
        List<ProductType> productTypes = productTypeService.productTypeTree();
        return Result.ok(productTypes);
    }

    //校验分类编码是否已经存在
    @RequestMapping("/verify-type-code")
    public Result checkTypeCode(String typeCode){
        return productTypeService.checkTypeCode(typeCode);
    }

    //添加商品分类
    @RequestMapping("/type-add")
    public Result addProductType(@RequestBody ProductType productType){
        return productTypeService.saveProductType(productType);
    }

    //删除商品分类
    @RequestMapping("/type-delete/{typeId}")
    public Result typeDelete(@PathVariable Integer typeId){
        return productTypeService.deleteProductType(typeId);
    }

    //修改商品分类
    @RequestMapping("/type-update")
    public Result updateProductType(@RequestBody ProductType productType){
        return productTypeService.setProductType(productType);
    }

}
